package com.jinhua.huaoj.judge.codesandbox;

import com.jinhua.huaoj.common.ErrorCode;
import com.jinhua.huaoj.exception.ThrowUtils;
import com.jinhua.huaoj.judge.model.ExecuteCodeRequest;
import com.jinhua.huaoj.judge.model.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 静态代理实现日志
 */
@Slf4j
public class CodeSandBoxProxy implements CodeSandBox {

    private final CodeSandBox codeSandBox;

    public CodeSandBoxProxy(CodeSandBox codeSandBox) {
        this.codeSandBox = codeSandBox;
    }


    @Override
    public ExecuteCodeResponse excuteCode(ExecuteCodeRequest executeCodeRequest) {
        log.info("代码沙箱执行参数: " + executeCodeRequest.toString());
        ExecuteCodeResponse executeCodeResponse = codeSandBox.excuteCode(executeCodeRequest);
        ThrowUtils.throwIf(executeCodeResponse == null, ErrorCode.SYSTEM_ERROR);
        log.info("代码沙箱执行结果: " + executeCodeResponse.toString());
        return executeCodeResponse;
    }
}
